using System;
using System.Collections;
using System.Collections.Generic;
using Main.Event;
using Main.Save;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using ZSW.Framework;
namespace Main.UI
{
    public class UI_SaveSlot : ZSWF_InitMonoBehaviour
    {
        public TMP_Text GameTime;
        public TMP_Text GameScene;
        public Button button;
        public int Index;
        private DataSlot currentData;

        public override void Init()
        {
            base.Init();
            this.Index = this.transform.GetSiblingIndex();
            button.onClick.AddListener(Load);
            SetupSlotUI();
        }

        private void OnEnable()
        {
            SetupSlotUI();
        }

        private void SetupSlotUI()
        {
            if (!IsInit)
                return;
            Debug.Log(Index);
            var load = ZSWF_IOCContainer.Get<SaveLoadManager>();
            currentData = load.DataSlots[this.Index];

            if (currentData != null && currentData.DataDict.Count > 0)
            {
                GameTime.text = currentData.DateTime;
                GameScene.text = currentData.SceneName;
            }
            else
            {
                GameTime.text = "No Data";
                GameScene.text = "No Data";
            }
        }

        public void Load()
        {
            if (currentData != null && currentData.DataDict.Count > 0)
            {
                ZSWF_IOCContainer.Get<SaveLoadManager>().Load(Index);
            }
            else
            {
                // TODO: new game
                MainEventSystem.CallStartNewGameEvent(Index);
            }
        }
    }
}